package com.toidep.bitmaputil;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Log4m {
	public static String sTag = "BongNgo";

	public static void setTag(String tag) {
		if (tag != null)
			sTag = tag;
	}

//	public static void i(String msg, String content, boolean writeFile, long start) {
//		  Calendar cal = Calendar.getInstance(); 
//		  long cur = System.currentTimeMillis();
//
//		  int millisecond = cal.get(Calendar.MILLISECOND);
//		  int second = cal.get(Calendar.SECOND);
//		  int minute = cal.get(Calendar.MINUTE);
//		        //12 hour format
//		  int hour = cal.get(Calendar.HOUR);
//		        //24 hour format
//		  int date = cal.get(Calendar.DATE);
//		  int month = cal.get(Calendar.MONTH);
//		if (msg == null)
//			return;
//		try {
//			if (writeFile != false) {
//				appendLog("NAME_APP: "+sTag + "- MSG: " + msg + "- NOIDUNG: " + content+"  TIME: "
//						+ " - millisecond: " + Integer.toString(millisecond)
//						+ " - second:  " + Integer.toString(second)
//						+ " - minute:  " + Integer.toString(minute)
//						+ " - hour:  " + Integer.toString(hour)
//						+ " - date/mothn:  " + Integer.toString(date) + " / " + Integer.toString(month)
//						+ " - curtime:  " + Long.toString(cur)
//						+ " - total time:  " + Long.toString(cur - start));
//
//			}
//			android.util.Log.i(sTag, String.format(msg, content));
//		} catch (Exception e) {
//			android.util.Log.e(sTag, "myProject", e);
//			android.util.Log.i(sTag, msg);
//		}
//	}

	public static void d(String msg, String time) {
		if (msg == null)
			return;
		try {
			android.util.Log.d(sTag, String.format(msg, time));
		} catch (Exception e) {
			android.util.Log.e(sTag, "myProject", e);
			android.util.Log.d(sTag, msg);
		}
	}

	public static void e(String msg, String time) {
		if (msg == null)
			return;
		try {
			android.util.Log.e(sTag, String.format(msg, time));
		} catch (Exception e) {
			android.util.Log.e(sTag, "myProject", e);
			android.util.Log.e(sTag, msg);
		}
	}

	public static void e(String msg, Throwable t) {
		if (msg == null)
			return;
		android.util.Log.e(sTag, msg, t);
	}
/**
 * write to file using for log check performace download images
 * 
 * @param : string descriptons
 * 
 * */
	
	public static void appendLog(String text)
	{       
	   File logFile = new File("sdcard/Filelog.txt");
	   if (!logFile.exists())
	   {
	      try
	      {
	         logFile.createNewFile();
	      } 
	      catch (IOException e)
	      {
	         // TODO Auto-generated catch block
	         e.printStackTrace();
	      }
	   }
	   try
	   {
	      //BufferedWriter for performance, true to set append to file flag
	      BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)); 
	      buf.append(text);
	      buf.newLine();
	      buf.close();
	   }
	   catch (IOException e)
	   {
	      // TODO Auto-generated catch block
	      e.printStackTrace();
	   }
	}
}